package com.mydroidchat.data;

import java.util.HashMap;
import java.util.Map;

public class ChatUser {
    private static Map<String, ChatUser> usersMap = new HashMap<String, ChatUser>();
    
    private String nick;

    private ChatUser(String nick) {
        this.nick = nick;
    }

    public String getNick() {
        return nick;
    }

    public static ChatUser getByName(String name) {
        ChatUser chatUser = usersMap.get(name);
        if (chatUser == null) {
            chatUser = new ChatUser(name);
            usersMap.put(name, chatUser);
        }
        return chatUser;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ChatUser)) {
            return false;
        }
        return nick.equals(((ChatUser) obj).getNick());
    }
}
